// 操作cookie
/**
 * 
 * @param {string} key 设置键
 * @param {string} value 设置值
 * @param {number} seconds 设置秒
 * @param {string} path 设置路径
 */
function setCookie(key, value, seconds, path = '/') {
    let date = new Date()
    date.setTime(date.getTime() - 8 * 3600 * 1000 + seconds * 1000)
    document.cookie = `${key}=${value};expires=${date};path=${path}`

}

/**
 * 获得cookie
 * @param {string} key 
 * @returns 
 */
function getCookie(key) {
    let cookies = document.cookie;
    if (!cookies) {
        return
    }
    let cookiesArr = cookies.split('; ')
    for (let i = 0; i < cookiesArr.length; i++) {
        let brr = cookiesArr[i].split('=')
        if (brr[0] === key) {
            return brr[1]
        }
    }
}

/**
 * 删除cookie
 * @param {string} key 
 * @param {string} path 
 */
function removeCookie(key, path = '/') {
    setCookie(key, null, -1, path)
}